package com.example.xlzx.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xlzx.entity.Appointment;
import com.example.xlzx.entity.vo.AppointmentPageVo;
import com.example.xlzx.result.Result;
import com.example.xlzx.service.IAppointmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 预约表 前端控制器
 * </p>
 *
 * @author 1
 * @since 2025-03-07
 */
@RestController
@Tag(name="预约信息")
@RequestMapping("/xlzx")
public class AppointmentController {
    @Autowired
    private IAppointmentService iAppointmentService;
    @Operation(summary = "添加预约信息")
    @PostMapping("/insertAppointment")
    public Result<Boolean> insertAppointment(@RequestBody Appointment appointment){
        return Result.ok(iAppointmentService.insertAppointment(appointment));
    }

    @Operation(summary = "删除预约")
    @DeleteMapping("/deleteAppointment/{appointmentId}")
    public Result<Boolean> deleteAppointment(@PathVariable Long appointmentId){
        return Result.ok(iAppointmentService.removeById(appointmentId));
    }

    @Operation(summary = "预约分页查询")
    @GetMapping("/appointment/page")
    public Result<Page<AppointmentPageVo>> page(@RequestParam(required = false) String phone, @RequestParam int page, @RequestParam int size){
        Page<Appointment> pageParam = new Page<>(page, size);
        Page<AppointmentPageVo> appointmentPageVoPage = iAppointmentService.appointmentPage(pageParam, phone);
        return Result.ok(appointmentPageVoPage);
    }

    @Operation(summary = "根据id查询用户预约信息")
    @GetMapping("/selectAllAppointment")
    public Result<List<AppointmentPageVo>> selectAllAppointment(@RequestParam Long userId){
        return Result.ok(iAppointmentService.selectAllAppointment(userId));
    }

    @Operation(summary = "确认预约或者驳回")
    @GetMapping("/appointment/config")
    public Result<Boolean> appointmentConfig(@RequestParam Long appointId, @RequestParam Integer status) {
        return Result.ok(iAppointmentService.appointmentConfig(appointId, status));
    }



    @Operation(summary = "医生查看预约分页查询")
    @GetMapping("/appointment/doctor/page")
    public Result<Page<AppointmentPageVo>> page(@RequestParam Long doctorId ,@RequestParam int page, @RequestParam int size){
        Page<Appointment> pageParam = new Page<>(page, size);
        Page<AppointmentPageVo> appointmentPageVoPage = iAppointmentService.appointmentDoctorPage(doctorId,pageParam);
        return Result.ok(appointmentPageVoPage);
    }
}
